package com.example.leavls.controller;

import com.example.leavls.pojo.Leaverecords;
import com.example.leavls.service.LeaveService;
import com.example.leavls.util.RespPageEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/leavls")
@CrossOrigin
public class leavlsContreoller {

    @Resource
    private LeaveService leaveService;

    @Resource
    private  UtilpageService utilpageService;

    /**
     * 根据页码和大小分页查询
     * @param page 当前页，默认为1
     * @param size 当前每页显示行数，默认为5
     * @return 页信息的实体
     */
    @GetMapping("/page")
    public RespPageEntity getAllUserByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer size) {
        return utilpageService.getAllUserByPage(page,size);
    }

    @PostMapping("/add")
    public  int add(@RequestBody Leaverecords leaverecords){
       return leaveService.addLeave(leaverecords);
    }
    @GetMapping("/del")
    public  int del(@RequestParam Integer id){
        return leaveService.delLeave(id);
    }
    @PostMapping("/upd")
    public int upd(@RequestBody Leaverecords leaverecords){
        return  leaveService.updLeave(leaverecords);
    }
    @GetMapping("/getOne")
    public Leaverecords getOne(@RequestParam Integer id){
       return leaveService.getOne(id);
    }
}
